<template>
  <div class="bg">
    <iframe id="child" :src="iframeSrc" style="width: 100%; height: 300%" @load="onIframeLoad"></iframe>
  </div>
</template>

<script>
export default {
  data() {
    return {
      iframeSrc: 'http://36.26.7.134:38080/photovoltaic-manager/index/portal.htm',
    }
  },
  methods: {
    onIframeLoad() {
      // 动态设置 cookie
      document.cookie = 'mycookie=myvalue; path=/; domain=36.26.7.134:38080; Secure; SameSite=None'

      // 访问 iframe 的内容
      const iframe = this.$refs.myIframe
      const iframeDocument = iframe.contentDocument || iframe.contentWindow.document

      // 在 iframe 中执行操作
      iframeDocument.cookie = 'mycookie=myvalue; path=/; domain=36.26.7.134:38080; Secure; SameSite=None'
      console.log('Cookie set in iframe')
    },
  },
}
</script>

<script>
export default {
  data() {
    return {
      iframeSrc: 'http://36.26.7.134:38080/photovoltaic-manager/index/portal.htm',
    }
  },
  //http://localhost:8080/#/previews
  mounted() {
    // 动态设置 cookie
    document.cookie =
      'JSESSIONID=AF0ABF07BE64E7350D4DB35F3E3C31B6;Path=/photovoltaic-manager;Domain=36.26.7.134:38080;Secure; SameSite=None'
  },
  methods: {
    onIframeLoad() {
      console.log('iframe loaded')
    },
  },
}
</script>

<style lang="scss" scoped>
.bg {
  display: flex;
  height: 1200px;
}
</style>
